<?php
class UsersController extends AppController
{
	var $name = 'Users';
	var $helpers = array('Html', 'Form', 'Javascript', 'Time');
	
    function login()
    {
        if (!empty($this->data))
        {

            if(($this->data['User']['username'] == $this->User->username)  && ($this->data['User']['password'] == $this->User->password))
            {

                $this->Session->write('User', $this->data['User']);

                // Now that we have them stored in a session, forward them on
                // to a landing page for the application.
				$this->Session->setFlash('Login successful.');
                $this->redirect('/admin/events/');
				exit();
            }
            // Else, they supplied incorrect data:
            else
            {
                $this->Session->setFlash('Error Logging in.');
            }
        }
    }

    function logout()
    {
        // Redirect users to this action if they click on a Logout button.
        // All we need to do here is trash the session information:

        $this->Session->delete('User');

        // And we should probably forward them somewhere, too...
     
        $this->redirect('/');
		exit();
    }
}
?>